/*

The Effect of Personalized Feedback on Small Enterprises' Finances in Uganda
Antonia Grohmann, Lukas Menkhoff, Helke Seitz

Table 3, Panel B

*/
     
use "filepath\Uganda_longterm.dta", clear


 
local sample=3
#del;
local 
tex_vars3 
rulethumb personalized treatment_DIW_Apr2018
;
#del cr  
  
     
  
	 
foreach spec in 1 2 3 4 5  {



   
  if `spec'==1 { 
   #del;
    local lhs 
	z_inv2_v0`sample'
	;
	local rhs  
    lz_inv2_v0`sample' personalized rulethumb treatment_DIW_Apr2018 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }
       
  
  
	if `spec'==2 { 
   #del;
    local lhs 
	z_sav6_v0`sample'
	;
	local rhs  
    lz_sav6_v0`sample' personalized rulethumb treatment_DIW_Apr2018 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }

	if `spec'==3 { 
   #del;
    local lhs 
	z_profit4_v0`sample'
	;
	local rhs  
    lz_profit4_v0`sample' personalized rulethumb treatment_DIW_Apr2018 ind2 ind3 ind4

	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }
  
	
    

	
         
    if `spec'==4 { 
   #del;
    local lhs 
	z_loan1_v0`sample'
	;
	local rhs  
    lz_loan1_v0`sample' personalized rulethumb treatment_DIW_Apr2018 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }
   
   

  if `spec'==5 { 
   #del;
    local lhs 
	total_index6_v0`sample'
	;
	local rhs  
    ltotal_index6_v0`sample' personalized rulethumb treatment_DIW_Apr2018 ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }              



	
	  foreach num of numlist 1 {

      `estcommand'  `lhs' `rhs'  if  sample_v0`sample'==1, `estoptions'
	   
	   local obs`spec'=e(N) 
	   test _b[personalized]-_b[rulethumb]=0
	   local ttest`spec'=r(p)
	   local r2`spec'=	e(r2)
	   sum `lhs' if control==1
	   local meany`spec'=r(mean)
	   local sdy`spec' =sqrt(r(Var))
	   

	  if ("`spec'"=="1" & "`num'"=="1") {
		 
		 
		   #del;
			est2vec est_v3b
				, 
				vars(`tex_vars3') 
				replace name(out`spec'`num');
				
				est2extlbl, addto(est_v3b) 
				intex("${TEMP_PATH}/texlabels_e_v01.tex") path(${ESTIMATION_PATH}) 
				replace dropall saving;
			 
						
		  #del cr
		 } /*if*/
		 else {
						est2vec est_v3b, addto(est_v3b) name(out`spec'`num')

		 } /*else*/
		 #del;
					est2tex8 est_v3b, replace preserve 
					path(${ESTIMATION_PATH})
					mark(starb) levels(90 95 99) digits(3) 
					fancy leadzero thousep;
					#del cr
		 
	  
	  
	  
}
}





foreach spec of numlist 1(1)5{

matrix matrixd[1,`spec']=round(`ttest`spec'',.01)
matrix matrixd[2,`spec']=round(`r2`spec'',.01)
matrix matrixd[3,`spec']=round(`meany`spec'',.01)
matrix matrixd[4,`spec']=round(`sdy`spec'',.01)
matrix matrixd[5,`spec']=round(`obs`spec'',.01)
matrix matrixd[6,`spec']=1
matrix matrixd[7,`spec']=1

}
 
matrix rownames matrixd =  A-B=0(p-value) R$2$ Mean(SD)of$y_t$in controlgroup Observations y${t-1}$covariate strata

matrix list matrixd
outtable using ${DESC_PATH}/est_v3b, mat(matrixd)  replace  f(%9.2f )



